<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">




  
  
    
    
  <script src="/ikaros/lib/pace/pace.min.js?v=1.0.2"></script>
  <link rel="stylesheet" href="/ikaros/lib/pace/pace-theme-minimal.min.css?v=1.0.2">





















<link rel="stylesheet" href="/ikaros/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/ikaros/css/main.css?v=7.0.1">


  <link rel="apple-touch-icon" sizes="180x180" href="/ikaros/images/favicon.ico?v=7.0.1">


  <link rel="icon" type="image/png" sizes="32x32" href="/ikaros/images/favicon.ico?v=7.0.1">


  <link rel="icon" type="image/png" sizes="16x16" href="/ikaros/images/favicon.ico?v=7.0.1">








<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/ikaros/',
    scheme: 'Gemini',
    version: '7.0.1',
    sidebar: {"position":"left","display":"post","offset":6,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="前言：由于是计算机专业，3年多的学习还是打下了一定的编程基础的。C语言可能忘得差不多了，PHP、Python还算拿得上手，加上之前在公司又看了一个多月的PHP，前端的只是虽然接触不多，但是第一周这些基础的课程还是能够自己写的出来的。对于十分基础的只是，在这里我就不写了。较多的还是记录我感兴趣的，或者我没有接触过的知识点，仅供参考和自我总结，谢谢！">
<meta name="keywords" content="html5,css3">
<meta property="og:type" content="article">
<meta property="og:title" content="记录我的大前端修行1.1">
<meta property="og:url" content="http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/index.html">
<meta property="og:site_name" content="ikaros&#39;blog">
<meta property="og:description" content="前言：由于是计算机专业，3年多的学习还是打下了一定的编程基础的。C语言可能忘得差不多了，PHP、Python还算拿得上手，加上之前在公司又看了一个多月的PHP，前端的只是虽然接触不多，但是第一周这些基础的课程还是能够自己写的出来的。对于十分基础的只是，在这里我就不写了。较多的还是记录我感兴趣的，或者我没有接触过的知识点，仅供参考和自我总结，谢谢！">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/1.png">
<meta property="og:updated_time" content="2019-03-22T05:22:53.550Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="记录我的大前端修行1.1">
<meta name="twitter:description" content="前言：由于是计算机专业，3年多的学习还是打下了一定的编程基础的。C语言可能忘得差不多了，PHP、Python还算拿得上手，加上之前在公司又看了一个多月的PHP，前端的只是虽然接触不多，但是第一周这些基础的课程还是能够自己写的出来的。对于十分基础的只是，在这里我就不写了。较多的还是记录我感兴趣的，或者我没有接触过的知识点，仅供参考和自我总结，谢谢！">
<meta name="twitter:image" content="http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/1.png">



  <link rel="alternate" href="/ikaros/atom.xml" title="ikaros'blog" type="application/atom+xml">




  <link rel="canonical" href="http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>记录我的大前端修行1.1 | ikaros'blog</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/ikaros/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">ikaros'blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">平安喜乐</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/ikaros/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/ikaros/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/ikaros/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/ikaros/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/ikaros/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    
  
  
  
  

  

  <a href="https://github.com/ikarosyu" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" style="fill: #222; color: #fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://ikarosyu.gitee.io/ikaros/ikaros/2019/03/19/h5-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="ikaros">
      <meta itemprop="description" content="like sunday like rain like apple and cinnamon">
      <meta itemprop="image" content="/ikaros/images/Misaka.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="ikaros'blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">记录我的大前端修行1.1

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-03-19 20:45:18" itemprop="dateCreated datePublished" datetime="2019-03-19T20:45:18+08:00">2019-03-19</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-03-22 13:22:53" itemprop="dateModified" datetime="2019-03-22T13:22:53+08:00">2019-03-22</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/ikaros/categories/大前端/" itemprop="url" rel="index"><span itemprop="name">大前端</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon">
            <i class="fa fa-eye"></i>
             阅读次数： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          
            <div class="post-symbolscount">
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">本文字数：</span>
                
                <span title="本文字数">3.6k</span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">3 分钟</span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="前言："><a href="#前言：" class="headerlink" title="前言："></a>前言：</h2><p>由于是计算机专业，3年多的学习还是打下了一定的编程基础的。C语言可能忘得差不多了，PHP、Python还算拿得上手，加上之前在公司又看了一个多月的PHP，前端的只是虽然接触不多，但是第一周这些基础的课程还是能够自己写的出来的。对于十分基础的只是，在这里我就不写了。较多的还是记录我感兴趣的，或者我没有接触过的知识点，仅供参考和自我总结，谢谢！</p>
<a id="more"></a>
<h1 id="day1、2、3"><a href="#day1、2、3" class="headerlink" title="day1、2、3"></a>day1、2、3</h1><h2 id="初识css"><a href="#初识css" class="headerlink" title="初识css"></a>初识css</h2><p>拿什么拯救你，我的HTML。</p>
<p>以前写PHP的时候，只是要写一些基本的前端页面，文本框啊、按钮啊、a标签啊之类的，那是必不可能又什么好看的样式的。自己查看<strong>没有css</strong>的网站时，就会发现html的标签属性使用是比较混乱的，CSS的出现，拯救了混乱的HTML，当让更加拯救了我们web开发者。 让我们的网页更加丰富多彩。</p>
<p>CSS的最大贡献就是： 让 HTML 从样式中解脱苦海， 实现了 HTML 专注去做 结构呈现。 而样式交给 CSS 后，你完全可以放心的早点洗洗睡了！</p>
<h3 id="css简介"><a href="#css简介" class="headerlink" title="css简介"></a>css简介</h3><p>CSS通常称为CSS样式表或层叠样式表（级联样式表），主要用于设置HTML页面中的文本内容（字体、大小、对齐方式等）、图片的外形（宽高、边框样式、边距等）以及版面的布局等外观显示样式。</p>
<p>CSS以HTML为基础，提供了丰富的功能，如字体、颜色、背景的控制及整体排版等，而且还可以针对不同的浏览器设置不同的样式。</p>
<h3 id="css样式规则"><a href="#css样式规则" class="headerlink" title="css样式规则"></a>css样式规则</h3><p>略！</p>
<p><img src="/ikaros/2019/03/19/h5-1/1.png" alt></p>
<p>还是放个图吧~~</p>
<h2 id="样式表的建立和优先级"><a href="#样式表的建立和优先级" class="headerlink" title="样式表的建立和优先级"></a>样式表的建立和优先级</h2><h3 id="内部样式表"><a href="#内部样式表" class="headerlink" title="内部样式表"></a>内部样式表</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;style type="text/css"&gt;</span><br><span class="line">    <span class="comment">/* css 语句 */</span></span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>
<h3 id="内联样式-行内样式"><a href="#内联样式-行内样式" class="headerlink" title="内联样式(行内样式)"></a>内联样式(行内样式)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;标签 style=&quot;属性:属性值; 属性:属性值;&quot;&gt;&lt;/标签&gt;</span><br></pre></td></tr></table></figure>
<h3 id="外部样式表"><a href="#外部样式表" class="headerlink" title="外部样式表"></a>外部样式表</h3><ul>
<li><p>创建</p>
</li>
<li><p>导入</p>
<p>方法一：</p>
<p>语法</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span>  <span class="attr">type</span>=<span class="string">"text/css"</span>  <span class="attr">href</span>=<span class="string">"目标文件的路径及文件名全称"</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<p>注意： link 是个单标签哦!!!</p>
<p>该语法中，link标签需要放在head头部标签中，并且必须指定link标签的三个属性，具体如下：</p>
<p><code>href</code>：定义所链接外部样式表文件的URL，可以是相对路径，也可以是绝对路径。</p>
<p><code>type</code>：定义所链接文档的类型，在这里需要指定为“text/css”，表示链接的外部文件为CSS样式表。</p>
<p><code>rel</code>：定义当前文档与被链接文档之间的关系，在这里需要指定为“stylesheet”，表示被链接的文档是一个样式表文件。</p>
<p>方法二：</p>
<p>语法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;style type=&quot;text/css&quot;&gt;</span><br><span class="line">@import url(目标文件的路径及文件名全称);</span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="css-常用选择符-选择器"><a href="#css-常用选择符-选择器" class="headerlink" title="css 常用选择符(选择器)"></a>css 常用选择符(选择器)</h2><p>要想将CSS样式应用于特定的HTML元素，首先需要找到该目标元素。在CSS中，执行这一任务的样式规则部分被称为选择器（选择符）。</p>
<h3 id="标签-元素-选择器"><a href="#标签-元素-选择器" class="headerlink" title="标签(元素)选择器"></a>标签(元素)选择器</h3><p>标签选择器是指用HTML标签名称作为选择器，按标签名称分类，为页面中某一类标签指定统一的CSS样式。其基本语法格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">标签名&#123;属性1:属性值1; 属性2:属性值2; 属性3:属性值3; &#125;  或者</span><br><span class="line">   元素名&#123;属性1:属性值1; 属性2:属性值2; 属性3:属性值3; &#125;</span><br></pre></td></tr></table></figure>
<h3 id="id-选择器"><a href="#id-选择器" class="headerlink" title="id 选择器"></a>id 选择器</h3><p>使用 <code>#</code> 进行标识 后面紧跟 id 名字</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#id名&#123;属性1:属性值1; 属性2:属性值2; 属性3:属性值3; &#125;</span><br></pre></td></tr></table></figure>
<p>说明</p>
<p>A）当我们使用id选择符时，应该为每个元素定义一个id属性 如：<code>&lt;div id=&quot;div1&quot;&gt;&lt;/div&gt;</code> </p>
<p>B）id选择符的语法格式是“#”加上自定义的id名 如：<code>#box{width:300px; height:300px;}</code></p>
<p>C) 起名时要取英文名，不能用关键字：(所有的标记和属性都是关键字) 如：<code>head</code>标记 </p>
<p>D）一个id名称只能对应文档中一个具体的元素对象，因为id只能定义页面中某一个唯一的元素对象。 E) 最大的用处：创建网页的外围结构。</p>
<h3 id="类-class-选择器"><a href="#类-class-选择器" class="headerlink" title="类(class)选择器"></a>类(class)选择器</h3><p>类选择器使用“.”（英文点号）进行标识，后面紧跟类名，其基本语法格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.类名&#123;属性1:属性值1; 属性2:属性值2; 属性3:属性值3; &#125;</span><br><span class="line"></span><br><span class="line"> 标签调用的时候用 class=“类名”  即可。</span><br></pre></td></tr></table></figure>
<p>类选择器最大的优势是可以为元素对象定义单独或相同的样式。</p>
<h3 id="id-选择器和类选择器的区别"><a href="#id-选择器和类选择器的区别" class="headerlink" title="id 选择器和类选择器的区别"></a>id 选择器和类选择器的区别</h3><p>W3C标准规定，在同一个页面内，不允许有相同名字的id对象出现，但是允许相同名字的class。</p>
<p>类选择器（class） 好比人的名字， 是可以多次重复使用的， 比如 张伟 王伟 李伟 李娜</p>
<p>id选择器 好比人的身份证号码， 全中国是唯一的， 不得重复。 只能使用一次。</p>
<h3 id="群组选择器"><a href="#群组选择器" class="headerlink" title="群组选择器"></a>群组选择器</h3><p>我们可以给标签指定多个类名，从而达到更多的选择目的。</p>
<p>注意：</p>
<ol>
<li>样式显示效果跟HTML元素中的类名先后顺序没有关系,受css样式书写的上下顺序有关。</li>
<li>各个类名中间用空格隔开。</li>
</ol>
<p>多类名选择器在后期布局比较复杂的情况下，还是较多使用的。</p>
<h3 id="群组选择器-1"><a href="#群组选择器-1" class="headerlink" title="群组选择器"></a>群组选择器</h3><p>语法：选择符1，选择符2，选择符3{属性：属性值;} 说明：当有多个选择符应用相同的样式时，可以将选择符用“，”分隔的方式，合并为一组。</p>
<h3 id="通配符选择器"><a href="#通配符选择器" class="headerlink" title="通配符选择器"></a>通配符选择器</h3><p>通配符选择器用“*”号表示，他是所有选择器中作用范围最广的，能匹配页面中所有的元素。其基本语法格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">*&#123;属性1:属性值1; 属性2:属性值2; 属性3:属性值3; &#125;</span><br></pre></td></tr></table></figure>
<h3 id="伪类选择器"><a href="#伪类选择器" class="headerlink" title="伪类选择器"></a>伪类选择器</h3><p>伪类可以用于文档状态的改变、动态的事件等，例如用户的鼠标点击某个元素、未被访问的链接。</p>
<p>语法：</p>
<p><code>a:link{属性:属性值;}</code> 超链接的初始状态</p>
<p><code>a:visited{属性:属性值;}</code> 超链接被访问后的状态</p>
<p><code>a:hover{属性:属性值;}</code> 鼠标划过超链接时的状态</p>
<p><code>a:active{属性:属性值;}</code> 鼠标按下时超链接的状态</p>
<p>要按照 :link –&gt; :visited –&gt; :hover –&gt; :active 的顺序。 错误的顺序有时会使超链接的样式失效</p>
<p>记忆口诀：</p>
<p><strong>lv</strong> 包包， <strong>ha</strong>o</p>
<h3 id="包含选择器"><a href="#包含选择器" class="headerlink" title="包含选择器"></a>包含选择器</h3><p>语法：选择符1 选择符2{属性：属性值;}</p>
<p>说明：</p>
<p>选择符1和选择符2用空格隔开，含义就是选择符1中包含的所有选择符2;</p>
<p>用法：当我的元素存在父级元素的时候，我要改变自己本身的样式，可以不另加选择符，直接用包含选择器的方式解决。</p>
<h2 id="权重"><a href="#权重" class="headerlink" title="权重"></a>权重</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">css中用四位数字表示权重，权重的表达方式如：0，0，0，0 </span><br><span class="line"></span><br><span class="line">类型选择符的权重为0001 </span><br><span class="line"></span><br><span class="line">class选择符的权重为0010</span><br><span class="line"></span><br><span class="line"> id选择符的权重为0100 </span><br><span class="line"></span><br><span class="line">伪类选择符的权重为0010  </span><br><span class="line"></span><br><span class="line">包含选择符的权重：为包含选择符的权中之和 内联样式的权重为1000 </span><br><span class="line"></span><br><span class="line">内联样式的权重为1000</span><br><span class="line"></span><br><span class="line">继承样式的权重为0000</span><br></pre></td></tr></table></figure>
<p><strong>当不同选择符的样式设置有冲突的时候，高权重选择 符的样式会覆盖低权重选择符的样式。</strong></p>
<p>例如：b .demo的权重是1+10=11 .demo的权重是10 所以经常会发生.demo的样式失效</p>
<p><strong>相同权重的选择符，样式遵循就近原则：哪个选择符最后定义，就采用哪个选择符样式。（注意：是css样式中定义该选择符的先后，而不是html中使用先后）</strong></p>
<h1 id="day4"><a href="#day4" class="headerlink" title="day4"></a>day4</h1><h2 id="拓展-补充-巴啦啦"><a href="#拓展-补充-巴啦啦" class="headerlink" title="拓展\补充\巴啦啦"></a>拓展\补充\巴啦啦</h2><h3 id="css书写方式"><a href="#css书写方式" class="headerlink" title="css书写方式"></a>css书写方式</h3><p>1、 内部样式表：<code>&lt;style&gt;&lt;/style&gt;</code> style标签放在head标签里面，卸载上边是因为代码从上往下执行，为了优先加载样式</p>
<p>2、 外部样式表：link href=”css文件路径”  type=”text/css”  rel=”stylesheet”</p>
<p>3、 行内样式表  css属性 style=””    “”里面不加{}   属性名:属性值;  </p>
<p>@charset “utf-8”;    一定加分号;</p>
<h3 id="css样式表优先级"><a href="#css样式表优先级" class="headerlink" title="css样式表优先级"></a>css样式表优先级</h3><p>行内样式表 优先级最高</p>
<p>外部样式表和内部样式表的优先级根据书写决定，后边的把前边的覆盖了，覆盖的是已经有的属性，没有的属性会叠加上去并且生效。</p>
<p><strong>！！！bgcolor 是HTML里面的属性，不适用css</strong></p>
<p>想要某一类元素有特有的属性</p>
<p>h1、P、div等这些HTML里面有的标签，都叫做元素（标签）选择器在什么情况下使用：所有的这个元素都要有这个属性的情况下</p>
<p>类选择器：.类名   想要某些元素有特定的属性</p>
<p>id选择器：不能重复，一个id只能有一个。</p>
<p>多类名选择器：class=”类名1 类名2”</p>
<p>群组选择器：个选择器之间用 , （英文状态下的逗号）隔开</p>
<p>包含选择器，是选择器的名称加空格，后面再跟上你要选择的元素</p>
<p><strong>float：浮动 让竖着排列的元素 横向排列</strong></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    
      <div>
        




  



<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>ikaros</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    
    <a href="http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/" title="记录我的大前端修行1.1">http://ikarosyu.gitee.io/ikaros/2019/03/19/h5-1/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/ikaros/tags/html5/" rel="tag"># html5</a>
          
            <a href="/ikaros/tags/css3/" rel="tag"># css3</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/ikaros/2019/03/19/record-h5/" rel="next" title="记录我的大前端修行1.0-启程计划">
                <i class="fa fa-chevron-left"></i> 记录我的大前端修行1.0-启程计划
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/ikaros/2019/03/20/h5-2/" rel="prev" title="记录我的大前端修行2.1">
                记录我的大前端修行2.1 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/ikaros/images/Misaka.png" alt="ikaros">
            
              <p class="site-author-name" itemprop="name">ikaros</p>
              <div class="site-description motion-element" itemprop="description">like sunday like rain like apple and cinnamon</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/ikaros/archives/">
                
                    <span class="site-state-item-count">14</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/ikaros/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">5</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/ikaros/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">13</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/ikaros/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/ikarosyu" title="GitHub &rarr; https://github.com/ikarosyu" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://ikarosyu@gmail.com" title="E-Mail &rarr; https://ikarosyu@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://twitter.com/ikarosyu" title="Twitter &rarr; https://twitter.com/ikarosyu" rel="noopener" target="_blank"><i class="fa fa-fw fa-twitter"></i>Twitter</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://steamcommunity.com/id/ikarosyu/" title="steam &rarr; https://steamcommunity.com/id/ikarosyu/" rel="noopener" target="_blank"><i class="fa fa-fw fa-steam"></i>steam</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://weibo.com/3024293020/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1" title="Weibo &rarr; https://weibo.com/3024293020/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="http://www.zhihu.com/people/ikaros-48?utm_source=qq&utm_medium=social&utm_oi=740688299089199104" title="知乎 &rarr; http://www.zhihu.com/people/ikaros-48?utm_source=qq&utm_medium=social&utm_oi=740688299089199104" rel="noopener" target="_blank"><i class="fa fa-fw fa-globe"></i>知乎</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="/ikaros/assets/qq.jpg" title="QQ &rarr; /assets/qq.jpg"><i class="fa fa-fw fa-qq"></i>QQ</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="/ikaros/assets/wechat.png" title="Wechat &rarr; /assets/wechat.png"><i class="fa fa-fw fa-wechat"></i>Wechat</a>
                </span>
              
            </div>
          

          
             <div class="cc-license motion-element" itemprop="license">
              
              
                
              
              
              
              <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" class="cc-opacity" rel="noopener" target="_blank"><img src="/ikaros/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
             </div>
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ikaros149.lofter.com/" title="http://ikaros149.lofter.com/" rel="noopener" target="_blank">ikarosyu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://sakurabaka.lofter.com/" title="http://sakurabaka.lofter.com/" rel="noopener" target="_blank">sukura</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="//www.google.com" title="//www.google.com">google</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言："><span class="nav-number">1.</span> <span class="nav-text">前言：</span></a></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#day1、2、3"><span class="nav-number"></span> <span class="nav-text">day1、2、3</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#初识css"><span class="nav-number">1.</span> <span class="nav-text">初识css</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#css简介"><span class="nav-number">1.1.</span> <span class="nav-text">css简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#css样式规则"><span class="nav-number">1.2.</span> <span class="nav-text">css样式规则</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#样式表的建立和优先级"><span class="nav-number">2.</span> <span class="nav-text">样式表的建立和优先级</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#内部样式表"><span class="nav-number">2.1.</span> <span class="nav-text">内部样式表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#内联样式-行内样式"><span class="nav-number">2.2.</span> <span class="nav-text">内联样式(行内样式)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#外部样式表"><span class="nav-number">2.3.</span> <span class="nav-text">外部样式表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css-常用选择符-选择器"><span class="nav-number">3.</span> <span class="nav-text">css 常用选择符(选择器)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#标签-元素-选择器"><span class="nav-number">3.1.</span> <span class="nav-text">标签(元素)选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#id-选择器"><span class="nav-number">3.2.</span> <span class="nav-text">id 选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#类-class-选择器"><span class="nav-number">3.3.</span> <span class="nav-text">类(class)选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#id-选择器和类选择器的区别"><span class="nav-number">3.4.</span> <span class="nav-text">id 选择器和类选择器的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#群组选择器"><span class="nav-number">3.5.</span> <span class="nav-text">群组选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#群组选择器-1"><span class="nav-number">3.6.</span> <span class="nav-text">群组选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通配符选择器"><span class="nav-number">3.7.</span> <span class="nav-text">通配符选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#伪类选择器"><span class="nav-number">3.8.</span> <span class="nav-text">伪类选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#包含选择器"><span class="nav-number">3.9.</span> <span class="nav-text">包含选择器</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#权重"><span class="nav-number">4.</span> <span class="nav-text">权重</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#day4"><span class="nav-number"></span> <span class="nav-text">day4</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#拓展-补充-巴啦啦"><span class="nav-number">1.</span> <span class="nav-text">拓展\补充\巴啦啦</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#css书写方式"><span class="nav-number">1.1.</span> <span class="nav-text">css书写方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#css样式表优先级"><span class="nav-number">1.2.</span> <span class="nav-text">css样式表优先级</span></a></li></ol></li></ol></li></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">ikaros</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">站点总字数：</span>
    
    <span title="站点总字数">50k</span>
  

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    
    <span title="站点阅读时长">46 分钟</span>
  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.0.1</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv" title="总访客量">
      <i class="fa fa-user"></i>
      网站总访客数 <span class="busuanzi-value" id="busuanzi_value_site_uv"></span> 人次. |
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="site-pv" title="总访问量">
      &nbsp;<i class="fa fa-eye"></i>
      总访问量 <span class="busuanzi-value" id="busuanzi_value_site_pv"></span> 次.
    </span>

</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/ikaros/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/ikaros/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/ikaros/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/ikaros/js/src/utils.js?v=7.0.1"></script>

  <script src="/ikaros/js/src/motion.js?v=7.0.1"></script>



  
  


  <script src="/ikaros/js/src/affix.js?v=7.0.1"></script>

  <script src="/ikaros/js/src/schemes/pisces.js?v=7.0.1"></script>




  
  <script src="/ikaros/js/src/scrollspy.js?v=7.0.1"></script>
<script src="/ikaros/js/src/post-details.js?v=7.0.1"></script>



  


  <script src="/ikaros/js/src/next-boot.js?v=7.0.1"></script>


  

  

  

  


  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/ikaros/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  

  

  

  

  

  

  

  
<script>
  $('.highlight').each(function(i, e) {
    var $wrap = $('<div>').addClass('highlight-wrap');
    $(e).after($wrap);
    $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function(e) {
      var code = $(this).parent().find('.code').find('.line').map(function(i, e) {
        return $(e).text();
      }).toArray().join('\n');
      var ta = document.createElement('textarea');
      var yPosition = window.pageYOffset || document.documentElement.scrollTop;
      ta.style.top = yPosition + 'px'; // Prevent page scroll
      ta.style.position = 'absolute';
      ta.style.opacity = '0';
      ta.readOnly = true;
      ta.value = code;
      document.body.appendChild(ta);
      ta.select();
      ta.setSelectionRange(0, code.length);
      ta.readOnly = false;
      var result = document.execCommand('copy');
      
        if (result) $(this).text('复制成功');
        else $(this).text('复制失败');
      
      ta.blur(); // For iOS
      $(this).blur();
    })).on('mouseleave', function(e) {
      var $b = $(this).find('.copy-btn');
      setTimeout(function() {
        $b.text('复制');
      }, 300);
    }).append(e);
  })
</script>


  

  

</body>
</html>
